package net.lab1024.smartadmin.module.business.engineExternalCharacteristic.controller;

import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.controller.BaseController;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.common.domain.ValidateList;
import net.lab1024.smartadmin.module.business.engine.domain.entity.EngineEntity;
import net.lab1024.smartadmin.module.business.engineExternalCharacteristic.domain.dto.EngineExternalCharacteristicAddDTO;
import net.lab1024.smartadmin.module.business.engineExternalCharacteristic.domain.dto.EngineExternalCharacteristicUpdateDTO;
import net.lab1024.smartadmin.module.business.engineExternalCharacteristic.domain.dto.EngineExternalCharacteristicQueryDTO;
import net.lab1024.smartadmin.module.business.engineExternalCharacteristic.domain.entity.EngineExternalCharacteristicEntity;
import net.lab1024.smartadmin.module.business.engineExternalCharacteristic.domain.vo.EngineExternalCharacteristicVO;
import net.lab1024.smartadmin.module.business.engineExternalCharacteristic.domain.vo.EngineExternalCharacteristicExcelVO;
import net.lab1024.smartadmin.module.business.engineExternalCharacteristic.service.EngineExternalCharacteristicService;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import org.apache.poi.ss.usermodel.Workbook;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * [ 发动机外特性曲线 ]
 *
 * @author wuhq
 * @version 1.0
 * @company 发动机外特性曲线
 * @copyright (c)  发动机外特性曲线Inc. All rights reserved.
 * @date 2021-11-07 11:15:38
 * @since JDK1.8
 */
@RestController
@Api(tags = {"发动机外特性曲线"})
public class EngineExternalCharacteristicController extends BaseController {

    @Autowired
    private EngineExternalCharacteristicService engineExternalCharacteristicService;

    @ApiOperation(value = "分页查询发动机外特性曲线",notes = "@author wuhq")
    @PostMapping("/engineExternalCharacteristic/page/query")
    public ResponseDTO<PageResultDTO<EngineExternalCharacteristicVO>> queryByPage(@RequestBody EngineExternalCharacteristicQueryDTO queryDTO) {
        return engineExternalCharacteristicService.queryByPage(queryDTO);
    }

    @ApiOperation(value = "添加发动机外特性曲线",notes = "@author wuhq")
    @PostMapping("/engineExternalCharacteristic/add")
    public ResponseDTO<String> add(@RequestBody @Validated EngineExternalCharacteristicAddDTO addTO){
        // 保存之前先删除旧的数据
        engineExternalCharacteristicService.delByEngineId(addTO.getEngineId());

        return engineExternalCharacteristicService.add(addTO);
    }

    @ApiOperation(value = "根据id获取数据",notes = "@author wuhq")
    @GetMapping("/engineExternalCharacteristic/getById/{id}")
    public ResponseDTO<EngineExternalCharacteristicEntity> getById(@PathVariable Long id) {
        return ResponseDTO.succData(engineExternalCharacteristicService.getById(id));
    }

    @ApiOperation(value = "根据发动机id获取数据",notes = "@author wuhq")
    @GetMapping("/engineExternalCharacteristic/getByEngineId/{engineId}")
    public ResponseDTO<EngineExternalCharacteristicEntity> getByEngineId(@PathVariable Long engineId) {
        return ResponseDTO.succData(engineExternalCharacteristicService.getByEngineId(engineId));
    }

    @ApiOperation(value="修改发动机外特性曲线",notes = "@author wuhq")
    @PostMapping("/engineExternalCharacteristic/update")
    public ResponseDTO<String> update(@RequestBody @Validated EngineExternalCharacteristicUpdateDTO updateDTO){
        return engineExternalCharacteristicService.update(updateDTO);
    }

    @ApiOperation(value="批量删除发动机外特性曲线",notes = "@author wuhq")
    @PostMapping("/engineExternalCharacteristic/deleteByIds")
    public ResponseDTO<String> delete(@RequestBody @Validated ValidateList<Long> idList) {
        return engineExternalCharacteristicService.deleteByIds(idList);
    }

    @ApiOperation(value = "批量导出", notes = "@author wuhq")
    @PostMapping("/engineExternalCharacteristic/export/batch")
    public void batchExport(@RequestBody @Validated ValidateList<Long> idList, HttpServletResponse response) {
        //查询数据
        List<EngineExternalCharacteristicExcelVO> engineExternalCharacteristicList = engineExternalCharacteristicService.queryBatchExportData(idList);
        //导出操作
        ExportParams ex = new ExportParams("发动机外特性曲线", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, EngineExternalCharacteristicExcelVO.class, engineExternalCharacteristicList);
        downloadExcel("发动机外特性曲线", workbook, response);
    }

    @ApiOperation(value = "导出全部", notes = "@author wuhq")
    @PostMapping("/engineExternalCharacteristic/export/all")
    public void exportAll(@RequestBody @Validated EngineExternalCharacteristicQueryDTO queryDTO, HttpServletResponse response) {
        //查询数据
        List<EngineExternalCharacteristicExcelVO> engineExternalCharacteristicList = engineExternalCharacteristicService.queryAllExportData(queryDTO);
        //导出操作
        ExportParams ex = new ExportParams("发动机外特性曲线", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, EngineExternalCharacteristicExcelVO.class, engineExternalCharacteristicList);
        downloadExcel("发动机外特性曲线", workbook, response);
    }

}
